SynchroMaster
 
 
 Bean SynchroMaster
 
Master for synchronous serial communication

Typical usage of the bean in user's code.

Typical Usage:

Required bean name is "SM1".
The following four typical usage modes are:

(1)
The easiest usage of the bean is a communication without interrupts (polling mode). This example sends zeros repeatedly until it receives a character with code 13 from the slave.


 MAIN.C

TComData ch;
byte err;

void main(void)
{
  do {
    SM1_SendChar(0);          // Send zero
    err = SM1_RecvChar(&ch);  // Get received char
    
  /* Do until it receives char with code 13 */ 
  } while ( (err != ERR_OK) || (ch != 13) );
:

(2)
The second typical usage of this bean is a communication with interrupts using communication events.

 MAIN.C

volatile bool Flag;

void main(void)
{
  Flag = FALSE;
  do {
    SM1_SendChar(0);  // Send zero

  /* Do until it  receives char with code 13 */ 
  } while (!Flag);
    :

 EVENTS.C

extern bool Flag;

void AM1_OnRxChar(void)
{
  byte ch;
byte err;  
  err = SM1_RecvChar(&ch);  // Get received char

  
  /* If it receives char with code 13 then Flag is set to TRUE */
  if ( (err == ERR_OK) && (ch == 13) )
    Flag = TRUE;
}

(3)
The following example shows how to recognize a communication error using the GetError method. In interrupt communication mode the user can use the OnError event to recognize the error during communication.


 MAIN.C

TComData ch;

void main(void)
{
  do {
    SM1_SendChar(0);          // Send zero
    err = SM1_RecvChar(&ch);  // Get received char
    
  /* Do until it receives char with code 13 */ 
  } while ( (err != ERR_OK) || (ch != 13) );
    :

 EVENTS.
C

void SM1_OnError(void)
{
  SM1_TError error; //TError union is defined in the header file

  /* Read the last communication errors */
  SM1_GetError(&error);
  
  /* If error OverRun occured then ... */
  if(error.errName.OverRun) { 
    :
  }
}

(4)
The next typical usage of this bean is a communication using DMA transfer. Interrupts can be enabled or disabled. This typical usage can be used on derivatives with DMA controller.

 MAIN.C

#define BLOCK_LENGTH  10

SM1_TComData SampleBlock[BLOCK_LENGTH];
word Snt, Rcv;

void main(void)
{
    :
  /* Enable DMA transfer from the receiver */
  (void)SM1_RecvBlock(&SampleBlock[0],BLOCK_LENGTH,&Rcv);
/* Send block of samples using DMA support */
  (void)SM1_SendBlock(&SampleBlock[0],BLOCK_LENGTH,&Snt);

  /* Wait for transmit/receive BLOCK_LENGTH samples */
  while (SM1_GetCharsInRxBuf() < BLOCK_LENGTH) {};
    :
}

For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.


Processor ExpertTM and Embedded BeansTM are registered trademarks of UNIS, Ltd.
©1997-2005, UNIS, Ltd.